﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;


namespace SachVietDLL.BLL
{
    public class CommentBLL
    {
        private BookDatabaseEntities db = new BookDatabaseEntities();

        //
        // GET: /Comment/

        public List<Commnet> GetAllComment()
        {
            var commnets = db.Commnets.Include(c => c.Account).Include(c => c.BookDetail);
            return commnets.ToList();
        }

        public List<Commnet> GetCommentByUser(string IDUser)
        {
            var query = from c in db.Commnets
                        where c.account_ID == IDUser
                        select c;
            return query.ToList();
        }

        public List<Commnet> GetCommentByBook(string IDBook)
        {
            var query = from c in db.Commnets
                        where c.account_ID == IDBook
                        select c;
            return query.ToList();
        }


        public void Create(Commnet commnet)
        {
            int count = db.Commnets.Count() + 1;
            String ID = "COMMENT" + count.ToString("000");
            commnet.comment_ID = ID;
            db.Commnets.Add(commnet);
            db.SaveChanges();    
        }

     
        public void Edit(Commnet commnet)
        {
            db.Entry(commnet).State = EntityState.Modified;
            db.SaveChanges();
        }

        public void Delete(string id)
        {
            Commnet commnet = db.Commnets.Find(id);
            db.Commnets.Remove(commnet);
            db.SaveChanges();
        }
    }
}